using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DataTransferObject;

namespace DataAccess
{
    public class clsNgonNguDAO:clsDataAccessHelper
    {
        // Fields
        private String tenTable;
        // Contructors
        public clsNgonNguDAO()
        {
            this.tenTable = "NGONNGU";
        }
        #region Methods
        public int KiemTraMaNNXoaDuocKhong(clsNgonNguDTO ngonngu)
        {
            String sql;
            DataTable tbl;
            try
            {
                sql = "select MANN from TUASACH";
                tbl = new DataTable();
                tbl = this.ExecuteQuery(sql);

                int flag = 0;
                foreach (DataRow dr in tbl.Rows)
                {
                    String ma = dr["MANN"].ToString().Trim();
                    if (ma == ngonngu.MaNN)
                    {
                        flag = 1;
                    }
                }
                return flag;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //-------------------------------------Lấy dữ liệu bảng Ngôn Ngữ-----------------------

        public DataTable SelectAll()
        {
            String sql;
            DataTable dt;
            try
            {
                sql = "SELECT * FROM " + this.tenTable;
                dt = new DataTable();
                dt = this.ExecuteQuery(sql);

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //-----------------------------------------------------------------------------//

        //-------------------------------------Thêm vào bảng Ngôn Ngữ-----------------------

        public bool Insert(clsNgonNguDTO ngonngu)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "INSERT INTO " + this.tenTable;
                sql += " values('";
                sql += ngonngu.MaNN + "',N'";
                sql += ngonngu.TenNN + "')";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }

        //-----------------------------------------------------------------------------//


        //-------------------------------------Xóa vào bảng Ngôn Ngữ-----------------------
        public bool Delete(clsNgonNguDTO ngonngu)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "DELETE ";
                sql += " FROM " + this.tenTable;
                sql += " WHERE MANN LIKE '" + ngonngu.MaNN + "'";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }



        //-----------------------------------------------------------------------------//

        //-------------------------------------Sửa vào bảng Ngôn Ngữ-----------------------

        public bool Update(clsNgonNguDTO ngonngu)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "UPDATE " + this.tenTable;
                sql += " SET";
                sql += " TENNN = N'";
                sql += ngonngu.TenNN + "'";
                sql += " WHERE MANN LIKE '";
                sql += ngonngu.MaNN + "'";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }


        //-----------------------------------------------------------------------------//


        #endregion


    }
}
